package com.bazinga.contact.view;

import java.sql.Time;
import java.util.Map;

import com.bazinga.contact.controller.StudentScheduleManager;
import com.bazinga.contact.controller.StudentSkillsManager;
import com.bazinga.contact.model.StudentSchedule;
import com.bazinga.contact.model.StudentSkills;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;


public class StudentAddInfoAction extends ActionSupport {

	private static final long serialVersionUID = 9149826260758390091L;
	private StudentSkills studentSkills; 
	private Long id;
	private Map<String, Object> session;
	private StudentSchedule studentSchedule;
	private String startTime;
	private String endTime;

	private StudentSkillsManager linkController;
	private StudentScheduleManager sslinkController;

	public StudentAddInfoAction() {
		linkController = new StudentSkillsManager();
		sslinkController = new StudentScheduleManager();
	}

	public String execute() {
		return SUCCESS;
	}

	public String addSkill() {
		this.session = ActionContext.getContext().getSession();
		if(session.containsKey("userid")) {
			
			studentSkills.setUserid( Long.parseLong((String)session.get("userid").toString()));
		}
		try {
			linkController.add(getStudentSkills());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	
	public String addSchedule() {
		this.session = ActionContext.getContext().getSession();
		if(session.containsKey("userid")) {
			studentSchedule.setUserid( Long.parseLong((String)session.get("userid").toString()));
		}
		try {
			studentSchedule.setStart_time(Time.valueOf(startTime));
			studentSchedule.setEnd_time(Time.valueOf(endTime));
			sslinkController.add(getStudentSchedule());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public String delete() {
		linkController.delete(getId());
		return SUCCESS;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	public StudentSkills getStudentSkills() {
		return studentSkills;
	}

	public void setStudentSkills(StudentSkills studentSkills) {
		this.studentSkills = studentSkills;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public StudentSchedule getStudentSchedule() {
		return studentSchedule;
	}

	public void setStudentSchedule(StudentSchedule studentSchedule) {
		this.studentSchedule = studentSchedule;
	}
	
}
